package com.wondertek.poms.core.filter.impl;

import com.wondertek.poms.core.filter.BaseRuleFilter;
import com.wondertek.poms.core.filter.RuleFilterChain;
import org.apache.commons.lang3.StringUtils;

import com.wondertek.poms.dao.po.Content;
import com.wondertek.poms.dao.po.IRulePo;
import com.wondertek.poms.dao.po.PrdInfoRule;


/**
 * <p><b>ContentTypeFilter Description:</b> 内容类别规则</p>
 * @author douzi
 * <b>DATE</b> 2019年9月27日 下午3:47:48
 */
public class ContentTypeFilter extends BaseRuleFilter {

	@Override
	public void doFilter(IRulePo rule, Content c, RuleFilterChain chain) {
		if (rule instanceof PrdInfoRule) {
			PrdInfoRule r = (PrdInfoRule) rule;
			this.baseFilter(r.getPrdRuleId(), r.getCategory(), 
					c.getCategory(), chain, "内容类别-Category");
		}
		chain.doFilter(rule, c, chain);
	}
	
	/**
	 * <p>Title: baseFilter</p>
	 * <p>Description: 覆盖上级方法，实现自己复杂业务,如果内容类别规则中为空，内容为图文的不能进入 </p>
	 * @param id
	 * @param ruleStr
	 * @param voStr
	 * @param chain
	 * @param comments
	 * @see
	 */
	protected void baseFilter(Long id, String ruleStr, String voStr, RuleFilterChain chain, String comments) {
		if (chain.isFlag() && StringUtils.isNotBlank(ruleStr)) {
            ruleStr = StringUtils.trim(ruleStr);
			chain.setFlag(Boolean.FALSE);
			String vo = StringUtils.trim(voStr);
			if (ruleStr.equals(vo)) {
				chain.setFlag(Boolean.TRUE);
			}
			
			log(id, chain, comments, ruleStr, vo);
		} else if (chain.isFlag() && StringUtils.isBlank(ruleStr)) {
			String vo = StringUtils.trim(voStr);
			if ("3".equals(vo)) {
				chain.setFlag(Boolean.FALSE);
			}
			
			log(id, chain, comments, ruleStr, vo);
		}
	}
}
